package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.CurrentAffairs;
import com.sc.nft.entity.dto.CurrentAffairsTypeDTO;
import com.sc.nft.entity.vo.CurrentAffairsAdminVO;
import com.sc.nft.entity.vo.CurrentAffairsDetailVo;
import com.sc.nft.entity.vo.CurrentAffairsDetailsVO;
import com.sc.nft.mapper.CurrentAffairsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 时政要闻表(sc_current_affairs)数据DAO
 *
 * @author zhangchao
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-03-05 10:52:52
 */
@Slf4j
@Repository
public class CurrentAffairsDao extends ServiceImpl<CurrentAffairsMapper, CurrentAffairs> {

    /**
     * 获取资讯分页数据
     *
     * @param page
     * @param currentAffairsTypeId
     * @param articleName
     * @return
     */
    public Page<CurrentAffairsAdminVO> adminCurrentAffairsVoPage(Page page, Long currentAffairsTypeId, String articleName) {
        return baseMapper.adminCurrentAffairsVoPage(page, currentAffairsTypeId, articleName);
    }

    /**
     * 删除资讯
     *
     * @param id
     * @return
     */
    public Boolean currentAffairsDelete(Long id) {
        LambdaUpdateWrapper<CurrentAffairs> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
        lambdaUpdateWrapper.eq(CurrentAffairs::getId, id);
        return remove(lambdaUpdateWrapper);
    }

    /**
     * 修改资讯展示字段
     *
     * @param id
     * @param isRecommend
     * @return
     */
    public Boolean currentAffairsShow(Long id, Boolean isRecommend) {
        LambdaUpdateWrapper<CurrentAffairs> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
        lambdaUpdateWrapper.eq(CurrentAffairs::getId, id);
        lambdaUpdateWrapper.set(CurrentAffairs::getIsShow, isRecommend);
        return update(lambdaUpdateWrapper);
    }

    /**
     * 修改资讯推荐位字段
     *
     * @param id
     * @param isRecommend
     * @return
     */
    public Boolean currentAffairsRecommend(Long id, Boolean isRecommend) {
        LambdaUpdateWrapper<CurrentAffairs> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
        lambdaUpdateWrapper.eq(CurrentAffairs::getId, id);
        lambdaUpdateWrapper.set(CurrentAffairs::getIsRecommend, isRecommend);
        return update(lambdaUpdateWrapper);
    }

    /**
     * 更新资讯内容
     *
     * @param currentAffairs
     * @return
     */
    public Boolean currentAffairsUpdate(CurrentAffairs currentAffairs) {
        LambdaUpdateWrapper<CurrentAffairs> wrapper = Wrappers.lambdaUpdate();
        wrapper.set(CurrentAffairs::getCurrentAffairsTypeId, currentAffairs.getCurrentAffairsTypeId());
        wrapper.set(CurrentAffairs::getCoverThumbnail, currentAffairs.getCoverThumbnail());
        wrapper.set(CurrentAffairs::getArticleName, currentAffairs.getArticleName());
        wrapper.set(CurrentAffairs::getContent, currentAffairs.getContent());
        wrapper.set(CurrentAffairs::getSort, currentAffairs.getSort());
        wrapper.set(CurrentAffairs::getContentSource, currentAffairs.getContentSource());
        wrapper.eq(CurrentAffairs::getId, currentAffairs.getId());
        return update(wrapper);
    }

    /**
     * APP获取推荐位
     *
     * @param id
     * @return
     */
    public List<CurrentAffairsDetailsVO> getCurrentAffairsRecommend(Long id) {
        return baseMapper.getCurrentAffairsRecommend(id);
    }

    /**
     * 获取后台资讯详情
     *
     * @param id
     * @return
     */
    public CurrentAffairsDetailsVO currentAffairsAdminDetails(Long id) {
        return baseMapper.currentAffairsAdminDetails(id);
    }

    /**
     * APP获取资讯详情
     *
     * @param id
     * @return
     */
    public CurrentAffairsDetailVo currentAffairsDetails(Long id) {
        return baseMapper.currentAffairsDetails(id);
    }

    /**
     * APP获取资讯
     *
     * @param currentAffairsTypeDTO
     * @return
     */
    public Page<CurrentAffairsDetailsVO> getCurrentAffairsRecommendPage(CurrentAffairsTypeDTO currentAffairsTypeDTO) {
        return baseMapper.getCurrentAffairsRecommendPage(currentAffairsTypeDTO.toMp(), currentAffairsTypeDTO.getId());
    }


}